<?php echo $this->atheme->form_open('', array('label'=>'Permissions')); ?>

<?php if(!$groups) return '';?>
<?php foreach($groups as $group): 
if(!$gpermissions = @$permissions[$group->pgroup_id]) continue;

?>
<!-- START table-responsive-->
<div class="panel panel-default">
<div class="table">
  <table id="table" class="table table-bordered table-hover">
	 <thead>
		<tr>
		   <th class="text-center"><?php echo @$group->pgroup_title;?></th>
		   <?php 
		   
		   foreach($permission_tab[$group->pgroup_id] as $r){
		   ?>
		   <th class="text-center"><?php echo $r;?></th>
		   <?php } ?>
		</tr>
	 </thead>
	 <tbody>
	 <?php foreach($gpermissions as $keyg=>$gpermission):
	 // prd($permission_tab);
	 ?>
		<tr>
		   <td class="text-center"><?php echo @$keyg?></td>
		    <?php  foreach($permission_tab[$group->pgroup_id] as $r){
				
		   ?>
		   <td class="text-center">
		   <?php if(isset($gpermission[$r]->permission_name)) { ?>
			  <div class="checkbox c-checkbox">
				 <label title="<?php echo $gpermission[$r]->permission_title;?>">
					<input type="checkbox" <?php echo ($this->auth->has_permission($gpermission[$r]->permission_name, $role_id)?'checked':'');?> name="per_id[<?php echo $gpermission[$r]->permission_id;?>]">
					<span class="fa fa-check"></span>
				 </label>
			  </div>
		   <?php } else echo 'Not used';?>
		   </td>
		    <?php } ?>
		   
		</tr>
		<?php endforeach;?>
	 </tbody>
  </table>
</div>
</div>


<?php endforeach;?>

<?php echo $this->atheme->form_submit(array(),array(), $role_id); ?>
<?php echo $this->atheme->form_close(); ?>